home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / CLASSINC.PAK / SETS.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  9KB  |  333 lines

  1. //----------------------------------------------------------------------------
  2. // Borland BIDS Container Library
  3. // Copyright (c) 1991, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   5.6  $
  6. //
  7. //----------------------------------------------------------------------------
  8. #if !defined(CLASSLIB_SETS_H)
  9. #define CLASSLIB_SETS_H
  10.  
  11. #if !defined(CLASSLIB_DEFS_H)
  12. # include <classlib/defs.h>
  13. #endif
  14. #if !defined(CLASSLIB_BAGS_H)
  15. # include <classlib/bags.h>
  16. #endif
  17. #if !defined(SERVICES_CHECKS_H)
  18. # include <services/checks.h>
  19. #endif
  20.  
  21. #pragma option -Vo-
  22. #if defined( BI_CLASSLIB_NO_po )
  23. # pragma option -po-
  24. #endif
  25.  
  26. #if defined(BI_NAMESPACE)
  27. namespace ClassLib {
  28. #endif
  29.  
  30. /*------------------------------------------------------------------------*/
  31. /*                                                                        */
  32. /*  template <class T,class Alloc> class TMSetAsVector                    */
  33. /*  template <class T,class Alloc> class TMSetAsVectorIterator            */
  34. /*                                                                        */
  35. /*  Implements a managed set of objects of type T, using a vector as      */
  36. /*  the underlying implementation.                                        */
  37. /*                                                                        */
  38. /*------------------------------------------------------------------------*/
  39.  
  40. template <class T, class Alloc> class TMSetAsVectorIterator;
  41.  
  42. template <class T,class Alloc> class TMSetAsVector :
  43.     private TMBagAsVector<T,Alloc>
  44. {
  45.  
  46.     typedef TMBagAsVector<T,Alloc> Parent;
  47.  
  48. public:
  49.  
  50.     friend TMSetAsVectorIterator<T,Alloc>;
  51.  
  52.     TMSetAsVector( unsigned sz = DEFAULT_SET_SIZE ) :
  53.         TMBagAsVector<T,Alloc>(sz)
  54.         {
  55.         }
  56.  
  57.     int Add( const T& );
  58.  
  59.     Parent::IterFunc;
  60.     Parent::CondFunc;
  61.     Parent::Detach;
  62.     Parent::HasMember;
  63.     Parent::Find;
  64.     Parent::IsEmpty;
  65.     Parent::IsFull;
  66.     Parent::GetItemsInContainer;
  67.     Parent::ForEach;
  68.     Parent::FirstThat;
  69.     Parent::LastThat;
  70.     Parent::Flush;
  71.  
  72. #if defined( BI_OLDNAMES )
  73.     void add( const T& t ) { Add(t); }
  74.     Parent::detach;
  75.     Parent::hasMember;
  76.     Parent::findMember;
  77.     Parent::isEmpty;
  78.     Parent::isFull;
  79.     Parent::getItemsInContainer;
  80.     Parent::forEach;
  81.     Parent::firstThat;
  82.     Parent::lastThat;
  83.     Parent::flush;
  84. #endif  // BI_OLDNAMES
  85.  
  86. };
  87.  
  88. template <class T,class Alloc> class TMSetAsVectorIterator :
  89.     public TMBagAsVectorIterator<T,Alloc>
  90. {
  91.  
  92. public:
  93.  
  94.     TMSetAsVectorIterator( const TMSetAsVector<T,Alloc>& s ) :
  95.         TMBagAsVectorIterator<T,Alloc>(s)
  96.         {
  97.         }
  98.  
  99. };
  100.  
  101. template <class T,class Alloc> int TMSetAsVector<T,Alloc>::Add( const T& t )
  102. {
  103.     if( HasMember(t) )
  104.         return 0;
  105.     else
  106.         return TMBagAsVector<T,Alloc>::Add(t);
  107. }
  108.  
  109. #if defined( BI_OLDNAMES )
  110. #define BI_MSetAsVector TMSetAsVector
  111. #define BI_MSetAsVectorIterator TMSetAsVectorIterator
  112. #endif
  113.  
  114. /*------------------------------------------------------------------------*/
  115. /*                                                                        */
  116. /*  template <class T> class TSetAsVector                                 */
  117. /*  template <class T> class TSetAsVectorIterator                         */
  118. /*                                                                        */
  119. /*  Implements a set of objects of type T, using a vector as              */
  120. /*  the underlying implementation and TStandardAllocator as its           */
  121. /*  memory manager.                                                       */
  122. /*                                                                        */
  123. /*------------------------------------------------------------------------*/
  124.  
  125. template <class T> class TSetAsVector :
  126.     public TMSetAsVector<T,TStandardAllocator>
  127. {
  128.  
  129. public:
  130.  
  131.     TSetAsVector( unsigned sz = DEFAULT_SET_SIZE ) :
  132.         TMSetAsVector<T,TStandardAllocator>(sz)
  133.         {
  134.         }
  135.  
  136. };
  137.  
  138. template <class T> class TSetAsVectorIterator :
  139.     public TMSetAsVectorIterator<T,TStandardAllocator>
  140. {
  141.  
  142. public:
  143.  
  144.     TSetAsVectorIterator( const TSetAsVector<T>& s ) :
  145.         TMSetAsVectorIterator<T,TStandardAllocator>(s)
  146.         {
  147.         }
  148.  
  149. };
  150.  
  151. #if defined( BI_OLDNAMES )
  152. #define BI_SetAsVector TSetAsVector
  153. #define BI_SetAsVectorIterator TSetAsVectorIterator
  154. #endif
  155.  
  156. /*------------------------------------------------------------------------*/
  157. /*                                                                        */
  158. /*  template <class T,class Alloc> class TMISetAsVector                   */
  159. /*  template <class T,class Alloc> class TMISetAsVectorIterator           */
  160. /*                                                                        */
  161. /*  Implements a managed set of pointers to objects of type T,            */
  162. /*  using a vector as the underlying implementation.                      */
  163. /*                                                                        */
  164. /*------------------------------------------------------------------------*/
  165.  
  166. template <class T, class Alloc> class TMISetAsVectorIterator;
  167.  
  168. template <class T,class Alloc> class TMISetAsVector :
  169.     private TMIBagAsVector<T,Alloc>
  170. {
  171.  
  172.     typedef TMIBagAsVector<T,Alloc> Parent;
  173.  
  174. public:
  175.  
  176.     friend TMISetAsVectorIterator<T,Alloc>;
  177.  
  178.     TMISetAsVector( unsigned sz = DEFAULT_SET_SIZE ) :
  179.         TMIBagAsVector<T,Alloc>(sz)
  180.         {
  181.         }
  182.  
  183.     int Add( T * );
  184.  
  185.     Parent::IterFunc;
  186.     Parent::CondFunc;
  187.     Parent::Detach;
  188.     Parent::HasMember;
  189.     Parent::Find;
  190.     Parent::IsEmpty;
  191.     Parent::IsFull;
  192.     Parent::GetItemsInContainer;
  193.     Parent::ForEach;
  194.     Parent::FirstThat;
  195.     Parent::LastThat;
  196.     Parent::Flush;
  197.     Parent::OwnsElements;
  198.  
  199. #if defined( BI_OLDNAMES )
  200.     void add( T *t ) { Add(t); }
  201.     Parent::detach;
  202.     Parent::findMember;
  203.     Parent::isEmpty;
  204.     Parent::isFull;
  205.     Parent::getItemsInContainer;
  206.     Parent::forEach;
  207.     Parent::firstThat;
  208.     Parent::lastThat;
  209.     Parent::flush;
  210.     Parent::ownsElements;
  211. #endif
  212.  
  213. };
  214.  
  215. #if defined( BI_OLDNAMES )
  216. #define BI_MISetAsVector TMISetAsVector
  217. #endif
  218.  
  219. template <class T,class Alloc>
  220. int TMISetAsVector<T,Alloc>::Add( T *t )
  221. {
  222.     if( HasMember(t) )
  223.         return 0;
  224.     else
  225.         return TMIBagAsVector<T,Alloc>::Add(t);
  226. }
  227.  
  228. template <class T,class Alloc> class TMISetAsVectorIterator :
  229.     public TMIBagAsVectorIterator<T,Alloc>
  230. {
  231.  
  232. public:
  233.  
  234.     TMISetAsVectorIterator( const TMISetAsVector<T,Alloc>& s ) :
  235.         TMIBagAsVectorIterator<T,Alloc>(s) {}
  236.  
  237. };
  238.  
  239. #if defined( BI_OLDNAMES )
  240. #define BI_MISetAsVectorIterator TMISetAsVectorIterator
  241. #endif
  242.  
  243. /*------------------------------------------------------------------------*/
  244. /*                                                                        */
  245. /*  template <class T> class TISetAsVector                                */
  246. /*  template <class T> class TISetAsVectorIterator                        */
  247. /*                                                                        */
  248. /*  Implements a set of pointers to objects of type T,                    */
  249. /*  using a vector as the underlying implementation and                   */
  250. /*  TStandardAllocator as its memory manager.                             */
  251. /*                                                                        */
  252. /*------------------------------------------------------------------------*/
  253.  
  254. template <class T> class TISetAsVector :
  255.     public TMISetAsVector<T,TStandardAllocator>
  256. {
  257.  
  258. public:
  259.  
  260.     TISetAsVector( unsigned sz = DEFAULT_SET_SIZE ) :
  261.         TMISetAsVector<T,TStandardAllocator>(sz)
  262.         {
  263.         }
  264.  
  265. };
  266.  
  267. template <class T> class TISetAsVectorIterator :
  268.     public TMISetAsVectorIterator<T,TStandardAllocator>
  269. {
  270.  
  271. public:
  272.  
  273.     TISetAsVectorIterator( const TISetAsVector<T>& s ) :
  274.         TMISetAsVectorIterator<T,TStandardAllocator>(s)
  275.         {
  276.         }
  277.  
  278. };
  279.  
  280. #if defined( BI_OLDNAMES )
  281. #define BI_ISetAsVector TISetAsVector
  282. #define BI_ISetAsVectorIterator TISetAsVectorIterator
  283. #endif
  284.  
  285. /*------------------------------------------------------------------------*/
  286. /*                                                                        */
  287. /*  template <class T> class TSet                                         */
  288. /*  template <class T> class TSetIterator                                 */
  289. /*                                                                        */
  290. /*  Easy names for TSetAsVector and TSetAsVectorIterator.                 */
  291. /*                                                                        */
  292. /*------------------------------------------------------------------------*/
  293.  
  294. template <class T> class TSet :
  295.     public TSetAsVector<T>
  296. {
  297.  
  298. public:
  299.  
  300.     TSet( unsigned sz = DEFAULT_SET_SIZE ) :
  301.         TSetAsVector<T>( sz )
  302.         {
  303.         }
  304.  
  305. };
  306.  
  307. template <class T> class TSetIterator :
  308.     public TSetAsVectorIterator<T>
  309. {
  310.  
  311. public:
  312.  
  313.  
  314.     TSetIterator( const TSet<T>& a ) :
  315.         TSetAsVectorIterator<T>(a)
  316.         {
  317.         }
  318.  
  319. };
  320.  
  321. #if defined(BI_NAMESPACE)
  322. }   // namespace ClassLib
  323. #endif
  324.  
  325. #if defined( BI_CLASSLIB_NO_po )
  326. #pragma option -po.
  327. #endif
  328.  
  329. #pragma option -Vo.
  330.  
  331. #endif  // CLASSLIB_SETS_H
  332.  
  333.